﻿/*

<javascriptresource>
<name>Test Adjustment Layers...</name>
<category>JSON Action Manager Tests</category>
</javascriptresource>

*/

//------------------------------------------------------------------------------
// File: Test Adjustment Layers.js
// Version: 3.3
// Release Date: 2012-10-21
// Copyright: © 2011-2012 Michel MARIANI <http://www.tonton-pixel.com/blog/>
// Licence: GPL <http://www.gnu.org/licenses/gpl.html>
//------------------------------------------------------------------------------
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
//------------------------------------------------------------------------------

//@includepath "~/JSON Action Manager/"
//@include "jamEngine.jsxinc"
//@include "jamHelpers.jsxinc"

//------------------------------------------------------------------------------

// Used to locate the test image and the HSL file
Folder.current = new Folder ("~/JSON Action Manager/tests/resources/");

//------------------------------------------------------------------------------

var adjustments =
{
    "Black and White":
    {
        "minVersion": 10    // CS3
    },
    "Brightness/Contrast":
    {
        "minVersion": 6 // "Use Legacy" parameter only from CS3...
    },
    "Channel Mixer":
    {
        "minVersion": 6
    },
    "Color Balance":
    {
        "minVersion": 6
    },
    "Curves":
    {
        "minVersion": 6
    },
    "Exposure":
    {
        "minVersion": 9 // CS2
    },
    "Gradient Map":
    {
        "minVersion": 6
    },
    "Hue/Saturation":
    {
        "minVersion": 6
    },
    "Invert":
    {
        "minVersion": 6
    },
    "Levels":
    {
        "minVersion": 6
    },
    "Photo Filter":
    {
        "minVersion": 8 // CS
    },
    "Posterize":
    {
        "minVersion": 6
    },
    "Selective Color":
    {
        "minVersion": 6
    },
    "Threshold":
    {
        "minVersion": 6
    },
    "Vibrance":
    {
        "minVersion": 11    // CS4
    }
};
var desiredAdjustment = null;
var allAdjustments = "*All*";
var reverseAllDocs = true;

//------------------------------------------------------------------------------

function getParameters ()
{
    var dialogWidth = 225;
    var dialogHeight = 300; // Dynamically adjusted anyway
    var dialogPadding = [ 15, 15 ];
    var panelPadding = [ 15, 15 ];
    var buttonWidth = 80;
    var buttonHeight = 20;
    var buttonGap = 5;
    var extraGap = (appVersion > 8) ? 0 : 12;
    var dlg = new Window ('dialog', "Test Adjustment Layers", [ 0, 0, dialogWidth, dialogHeight ]);
    dlg.btnPnl = dlg.add ('panel', [ dialogPadding[0], dialogPadding[1], dialogWidth - dialogPadding[0], dialogHeight - dialogPadding[1] ], 'Adjustment Layer');
    dlg.btnPnl.horizBtn = [];
    var y = panelPadding[1] + extraGap;
    for (var k in adjustments)
    {
        if (adjustments.hasOwnProperty (k))
        {
            dlg.btnPnl.horizBtn.push (dlg.btnPnl.add ('radiobutton', [ panelPadding[0], y, (dlg.btnPnl.bounds.right - dlg.btnPnl.bounds.left) - panelPadding[0], y + buttonHeight ], k));
            y += buttonHeight + buttonGap;
        }
    }
    dlg.btnPnl.horizBtn.push (dlg.btnPnl.add ('radiobutton', [ panelPadding[0], y, (dlg.btnPnl.bounds.right - dlg.btnPnl.bounds.left) - panelPadding[0], y + buttonHeight ], allAdjustments));
    y += buttonHeight + buttonGap;
    var count = dlg.btnPnl.horizBtn.length;
    for (var i = 0; i < count; i++)
    {
        var radbut = dlg.btnPnl.horizBtn[i];
        radbut.enabled = (radbut.text === allAdjustments) || (appVersion >= adjustments[radbut.text]["minVersion"]);
        radbut.value = false;
        radbut.onClick = function () { desiredAdjustment = this.text; };
    }
    for (var i = 0; i < count; i++)
    {
        var radbut = dlg.btnPnl.horizBtn[i];
        if (radbut.enabled)
        {
            radbut.value = true;
            desiredAdjustment = radbut.text;
            break;
        }
    }
    dlg.btnPnl.bounds.bottom = dlg.btnPnl.bounds.top + y + panelPadding[1];
    dlg.bounds.bottom = dlg.bounds.top + dialogPadding[1] + (dlg.btnPnl.bounds.bottom - dlg.btnPnl.bounds.top) + dialogPadding[1] + buttonHeight + dialogPadding[1];
    dlg.cancelBtn = dlg.add ('button', [ dialogPadding[0], dlg.bounds.bottom - dialogPadding[1] - buttonHeight, dialogPadding[0] + buttonWidth, dlg.bounds.bottom - dialogPadding[1] ], 'Cancel', { name: "cancel" });
    dlg.cancelBtn.onClick = function () { this.parent.close (false); };
    dlg.OKBtn = dlg.add ('button', [ dlg.bounds.right - dialogPadding[0] - buttonWidth, dlg.bounds.bottom - dialogPadding[1] - buttonHeight, dlg.bounds.right - dialogPadding[0], dlg.bounds.bottom - dialogPadding[1] ], 'OK', { name: "ok" });
    dlg.OKBtn.enabled = (desiredAdjustment in adjustments);
    dlg.OKBtn.onClick = function () { this.parent.close (true); };
    dlg.center ();
    return dlg.show ();
}

//------------------------------------------------------------------------------

function processAdjustment (desiredAdjustment)
{
    jamEngine.jsonPlay
    (
        "duplicate",
        {
            "target": { "<reference>": [ { "document": { "<enumerated>": { "ordinal": "first" } } } ] },
            "name": { "<string>": "Test Adjustment Layers | " + desiredAdjustment },
            "merged": { "<boolean>": true }
        }
    );
    switch (desiredAdjustment)
    {
        case "Black and White":
            jamEngine.jsonPlay
            (
                "make",
                {
                    "target": { "<reference>": [ { "adjustmentLayer": { "<class>": null } } ] },
                    "using":
                    {
                        "<object>":
                        {
                            "adjustmentLayer":
                            {
                                "name": { "<string>": "Black and White" },
                                "type":
                                {
                                    "<object>":
                                    {
                                        "blackAndWhite":
                                        {
                                            "red": { "<integer>": 70 },
                                            "yellow": { "<integer>": 128 },
                                            "green": { "<integer>": 24 },
                                            "cyan": { "<integer>": 0 },
                                            "blue": { "<integer>": -7 },
                                            "magenta": { "<integer>": 65 },
                                            "useTint": { "<boolean>": true },
                                            "tintColor": jamHelpers.toColorObject ([ "HSBColorClass", [ 40, 15, 70 ] ])
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            );
            break;
        case "Brightness/Contrast":
            jamEngine.jsonPlay
            (
                "make",
                {
                    "target": { "<reference>": [ { "adjustmentLayer": { "<class>": null } } ] },
                    "using":
                    {
                        "<object>":
                        {
                            "adjustmentLayer":
                            {
                                "name": { "<string>": "Brightness/Contrast | Soft Light" },
                                "mode": { "<enumerated>": { "blendMode": "softLight" } },
                                "type": { "<object>": { "brightnessContrast": { } } }   // or { "brightnessContrast": null }
                            }
                        }
                    }
                }
            );
            jamEngine.jsonPlay
            (
                "make",
                {
                    "target": { "<reference>": [ { "adjustmentLayer": { "<class>": null } } ] },
                    "using":
                    {
                        "<object>":
                        {
                            "adjustmentLayer":
                            {
                                "name": { "<string>": "Brightness/Contrast" },
                                "type":
                                {
                                    "<object>":
                                    {
                                        "brightnessContrast":
                                        {
                                            "brightness": { "<integer>": 10 },
                                            "contrast": { "<integer>": 20 },
                                            "useLegacy": { "<boolean>": true }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            );
            jamEngine.jsonPlay
            (
                "make",
                {
                    "target": { "<reference>": [ { "adjustmentLayer": { "<class>": null } } ] },
                    "using":
                    {
                        "<object>":
                        {
                            "adjustmentLayer":
                            {
                                "name": { "<string>": "Brightness/Contrast" },
                                "type":
                                {
                                    "<object>":
                                    {
                                        "brightnessContrast":
                                        {
                                            "brightness": { "<integer>": 10 },
                                            "contrast": { "<integer>": 20 },
                                            "useLegacy": { "<boolean>": false }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            );
            break;
        case "Channel Mixer":
            jamEngine.jsonPlay
            (
                "make",
                {
                    "target": { "<reference>": [ { "adjustmentLayer": { "<class>": null } } ] },
                    "using":
                    {
                        "<object>":
                        {
                            "adjustmentLayer":
                            {
                                "name": { "<string>": "Channel Mixer Color Shift" },
                                "type":
                                {
                                    "<object>":
                                    {
                                        "channelMixer":
                                        {
                                            "red":
                                            {
                                                "<object>":
                                                {
                                                    "channelMatrix":
                                                    {
                                                        "blue": { "<unitDouble>": { "percentUnit": 100 } }
                                                    }
                                                }
                                            },
                                            "green":
                                            {
                                                "<object>":
                                                {
                                                    "channelMatrix":
                                                    {
                                                        "red": { "<unitDouble>": { "percentUnit": 100 } }
                                                    }
                                                }
                                            },
                                            "blue":
                                            {
                                                "<object>":
                                                {
                                                    "channelMatrix":
                                                    {
                                                        "green": { "<unitDouble>": { "percentUnit": 100 } }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            );
            jamEngine.jsonPlay
            (
                "make",
                {
                    "target": { "<reference>": [ { "adjustmentLayer": { "<class>": null } } ] },
                    "using":
                    {
                        "<object>":
                        {
                            "adjustmentLayer":
                            {
                                "name": { "<string>": "Channel Mixer Monochrome" },
                                "type":
                                {
                                    "<object>":
                                    {
                                        "channelMixer":
                                        {
                                            "monochromatic": { "<boolean>": true },
                                            "gray":
                                            { 
                                                "<object>":
                                                {
                                                    "channelMatrix":
                                                    {
                                                        "red": { "<unitDouble>": { "percentUnit": 66 } },
                                                        "green": { "<unitDouble>": { "percentUnit": 33 } },
                                                        "blue": { "<unitDouble>": { "percentUnit": 19 } },
                                                        "constant": { "<unitDouble>": { "percentUnit": -18 } }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            );
            break;
        case "Color Balance":
            jamEngine.jsonPlay
            (
                "make",
                {
                    "target": { "<reference>": [ { "adjustmentLayer": { "<class>": null } } ] },
                    "using":
                    {
                        "<object>":
                        {
                            "adjustmentLayer":
                            {
                                "name": { "<string>": "Color Balance" },
                                "type":
                                {
                                    "<object>":
                                    {
                                        "colorBalance":
                                        {
                                            "shadowLevels": jamHelpers.toIntegerList ([ 9, 29, 48 ]),
                                            "midtoneLevels": jamHelpers.toIntegerList ([ 42, 5, 19 ]),
                                            "highlightLevels": jamHelpers.toIntegerList ([ -15, 20, -25 ]),
                                            "preserveLuminosity": { "<boolean>": true }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            );
            break;
        case "Curves":
            var compositeCurve = [ "composite", [ "curve", [ [ 0, 0 ], [ 77, 51 ], [ 178, 204 ], [ 255, 255 ] ] ] ];
            var redMapping =
            [
                "red",
                [
                    "mapping",
                    [
                        120, 121, 121, 122, 122, 123, 124, 124, 125, 126, 126, 127, 128, 128, 129, 130,
                        131, 131, 132, 133, 134, 135, 136, 136, 137, 138, 139, 140, 141, 142, 143, 143,
                        144, 145, 146, 147, 148, 148, 149, 150, 151, 151, 152, 153, 154, 154, 155, 155,
                        156, 157, 157, 158, 158, 159, 160, 160, 161, 162, 162, 163, 164, 164, 165, 165,
                        166, 166, 167, 167, 167, 168, 168, 169, 169, 170, 171, 172, 172, 173, 173, 173,
                        174, 175, 176, 177, 178, 179, 180, 180, 181, 182, 183, 183, 183, 184, 185, 185,
                        186, 186, 186, 183, 182, 180, 177, 175, 171, 168, 163, 162, 160, 158, 156, 153,
                        152, 149, 147, 144, 143, 140, 138, 135, 133, 130, 127, 124, 121, 117, 116, 114,
                        112, 109, 105, 103, 101,  99,  97,  94,  93,  90,  87,  83,  81,  76,  74,  74,
                         75,  76,  77,  78,  79,  80,  81,  82,  82,  83,  84,  85,  86,  87,  88,  90,
                         91,  92,  93,  94,  95,  96,  96,  97,  98,  99,  99, 100, 101, 102, 103, 104,
                        104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 114, 115, 115, 116, 116,
                        117, 117, 118, 119, 119, 118, 116, 112, 111, 109, 107, 106, 103, 101,  99,  97,
                         94,  91,  90,  87,  85,  83,  80,  77,  76,  74,  72,  71,  69,  66,  65,  63,
                         60,  58,  56,  53,  52,  50,  49,  47,  45,  44,  41,  39,  37,  34,  31,  30,
                         28,  26,  23,  22,  20,  17,  15,  15,  14,  12,  11,  10,   8,   8,   7,   6
                    ]
                ]
            ];
            var greenCurve = [ "green", [ "curve", [ [ 0, 255 ], [ 77, 51 ], [ 178, 204 ], [ 255, 0 ] ] ] ];
            var blueCurve = [ "blue", [ "curve", [ [ 0, 255 ], [ 255, 0 ] ] ] ];
            var curves = [ compositeCurve, redMapping, greenCurve, blueCurve ];
            jamEngine.jsonPlay
            (
                "make",
                {
                    "target": { "<reference>": [ { "adjustmentLayer": { "<class>": null } } ] },
                    "using":
                    {
                        "<object>":
                        {
                            "adjustmentLayer":
                            {
                                "name": { "<string>": "Curves" },
                                "type":
                                {
                                    "<object>":
                                    {
                                        "curves":
                                        {
                                            "adjustment": jamHelpers.toCurvesAdjustmentList (curves)
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            );
            break;
        case "Exposure":
            jamEngine.jsonPlay
            (
                "make",
                {
                    "target": { "<reference>": [ { "adjustmentLayer": { "<class>": null } } ] },
                    "using":
                    {
                        "<object>":
                        {
                            "adjustmentLayer":
                            {
                                "name": { "<string>": "Exposure" },
                                "type":
                                {
                                    "<object>":
                                    {
                                        "exposure":
                                        {
                                            "exposure": { "<double>": 1.0 },
                                            "offset": { "<double>": 0.0 },
                                            "gammaCorrection": { "<double>": 0.5 }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            );
            break;
        case "Gradient Map":
            var colorNoiseGradientArr =
            [
                "Color Noise",
                "colorNoise",
                345807450,  // randomSeed
                false,  // showTransparency
                true,   // vectorColor
                1024,   // smoothness 25% [4096 => 100%]
                "RGBColor",
                [ 0, 18, 25, 0 ],
                [ 100, 60, 73, 100 ]
            ];
            jamEngine.jsonPlay
            (
                "make",
                {
                    "target": { "<reference>": [ { "adjustmentLayer": { "<class>": null } } ] },
                    "using":
                    {
                        "<object>":
                        {
                            "adjustmentLayer":
                            {
                                "name": { "<string>": "Gradient Map | Darken" },
                                "mode": { "<enumerated>": { "blendMode": "darken" } },
                                "type":
                                {
                                    "<object>":
                                    {
                                        "gradientMapClass":
                                        {
                                            "reverse": { "<boolean>": false },
                                            "dither": { "<boolean>": false },
                                            "gradient": jamHelpers.toGradientObject (colorNoiseGradientArr)
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            );
            var customStopsGradientArr =
            [
                "Blue, Red, Yellow",
                "customStops",
                4096,
                [
                    [ 0, 50, "userStop", [ "RGBColor", [ 10, 0, 178 ] ] ],
                    [ 2048, 50, "userStop", [ "RGBColor", [ 255, 0, 0 ] ] ],
                    [ 4096, 50, "userStop", [ "RGBColor", [ 255, 252, 0 ] ] ]
                ]
            ];
            jamEngine.jsonPlay
            (
                "make",
                {
                    "target": { "<reference>": [ { "adjustmentLayer": { "<class>": null } } ] },
                    "using":
                    {
                        "<object>":
                        {
                            "adjustmentLayer":
                            {
                                "name": { "<string>": "Gradient Map | Difference" },
                                "mode": { "<enumerated>": { "blendMode": "difference" } },
                                "type":
                                {
                                    "<object>":
                                    {
                                        "gradientMapClass":
                                        {
                                            "reverse": { "<boolean>": true },
                                            "dither": { "<boolean>": false },
                                            "gradient": jamHelpers.toGradientObject (customStopsGradientArr)
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            );
            break;
        case "Hue/Saturation":
            jamEngine.jsonPlay
            (
                "make",
                {
                    "target": { "<reference>": [ { "adjustmentLayer": { "<class>": null } } ] },
                    "using":
                    {
                        "<object>":
                        {
                            "adjustmentLayer":
                            {
                                "name": { "<string>": "Color Ranges Saturation" },
                                "type":
                                {
                                    "<object>":
                                    {
                                        "hueSaturation":
                                        {
                                            "colorize": { "<boolean>": false },
                                            "adjustment": jamHelpers.toHueSatAdjustmentV2List ([ [ 1, 315, 345, 15, 45, 0, 50, 0 ], [ 3, 75, 105, 135, 165, 0, 60, 0 ] ])
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            );
            jamEngine.jsonPlay
            (
                "make",
                {
                    "target": { "<reference>": [ { "adjustmentLayer": { "<class>": null } } ] },
                    "using":
                    {
                        "<object>":
                        {
                            "adjustmentLayer":
                            {
                                "name": { "<string>": "Preset Hue" },
                                "type": { "<object>": { "hueSaturation": { "using": { "<path>": "Eerie.ahu" } } } }
                            }
                        }
                    }
                }
            );
            jamEngine.jsonPlay
            (
                "make",
                {
                    "target": { "<reference>": [ { "adjustmentLayer": { "<class>": null } } ] },
                    "using":
                    {
                        "<object>":
                        {
                            "adjustmentLayer":
                            {
                                "name": { "<string>": "Direct Hue" },
                                "type":
                                {
                                    "<object>":
                                    {
                                        "hueSaturation":
                                        {
                                            "colorize": { "<boolean>": false },
                                            "adjustment": jamHelpers.toHueSatAdjustmentV2List ([ [ 130, 0, 0 ] ])
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            );
            jamEngine.jsonPlay
            (
                "make",
                {
                    "target": { "<reference>": [ { "adjustmentLayer": { "<class>": null } } ] },
                    "using":
                    {
                        "<object>":
                        {
                            "adjustmentLayer":
                            {
                                "name": { "<string>": "Cyanotype Colorize" },
                                "type":
                                {
                                    "<object>":
                                    {
                                        "hueSaturation":
                                        {
                                            "colorize": { "<boolean>": true },
                                            "adjustment": jamHelpers.toHueSatAdjustmentV2List ([ [ 210, 30, 10 ] ])
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            );
            break;
        case "Invert":
            jamEngine.jsonPlay
            (
                "make",
                {
                    "target": { "<reference>": [ { "adjustmentLayer": { "<class>": null } } ] },
                    "using":
                    {
                        "<object>":
                        {
                            "adjustmentLayer":
                            {
                                "name": { "<string>": "Invert | Color" },
                                "mode": { "<enumerated>": { "blendMode": "color" } },
                                "type": { "<class>": "invert" }
                            }
                        }
                    }
                }
            );
            jamEngine.jsonPlay
            (
                "make",
                {
                    "target": { "<reference>": [ { "adjustmentLayer": { "<class>": null } } ] },
                    "using":
                    {
                        "<object>":
                        {
                            "adjustmentLayer":
                            {
                                "name": { "<string>": "Invert | Luminosity" },
                                "mode": { "<enumerated>": { "blendMode": "luminosity" } },
                                "type": { "<object>": { "invert": null } }
                            }
                        }
                    }
                }
            );
            break;
        case "Levels":
            jamEngine.jsonPlay
            (
                "make",
                {
                    "target": { "<reference>": [ { "adjustmentLayer": { "<class>": null } } ] },
                    "using":
                    {
                        "<object>":
                        {
                            "adjustmentLayer":
                            {
                                "name": { "<string>": "Auto Contrast" },
                                "type":
                                {
                                    "<object>":
                                    {
                                        "levels":
                                        {
                                            "adjustment":
                                            {
                                                "<list>":
                                                [
                                                    {
                                                        "<object>":
                                                        {
                                                            "levelsAdjustment":
                                                            {
                                                                "channel": jamHelpers.toChannelReference ("composite"),
                                                                "autoContrast": { "<boolean>": true },
                                                                "blackClip": { "<double>": 0.1 },
                                                                "whiteClip": { "<double>": 0.1 }
                                                            }
                                                        }
                                                    }
                                                ]
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            );
            jamEngine.jsonPlay
            (
                "make",
                {
                    "target": { "<reference>": [ { "adjustmentLayer": { "<class>": null } } ] },
                    "using":
                    {
                        "<object>":
                        {
                            "adjustmentLayer":
                            {
                                "name": { "<string>": "Auto Levels / Auto Tone" },
                                "type":
                                {
                                    "<object>":
                                    {
                                        "levels":
                                        {
                                            "adjustment":
                                            {
                                                "<list>":
                                                [
                                                    {
                                                        "<object>":
                                                        {
                                                            "levelsAdjustment":
                                                            {
                                                                "channel": jamHelpers.toChannelReference ("composite"),
                                                                "auto": { "<boolean>": true },
                                                                "blackClip": { "<double>": 0.1 },
                                                                "whiteClip": { "<double>": 0.1 }
                                                            }
                                                        }
                                                    }
                                                ]
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            );
            jamEngine.jsonPlay
            (
                "make",
                {
                    "target": { "<reference>": [ { "adjustmentLayer": { "<class>": null } } ] },
                    "using":
                    {
                        "<object>":
                        {
                            "adjustmentLayer":
                            {
                                "name": { "<string>": "Auto Color" },
                                "type":
                                {
                                    "<object>":
                                    {
                                        "levels":
                                        {
                                            "adjustment":
                                            {
                                                "<list>":
                                                [
                                                    {
                                                        "<object>":
                                                        {
                                                            "levelsAdjustment":
                                                            {
                                                                "channel": jamHelpers.toChannelReference ("composite"),
                                                                "autoBlackWhite": { "<boolean>": true },
                                                                "autoNeutrals": { "<boolean>": true },
                                                                "blackClip": { "<double>": 0.1 },
                                                                "whiteClip": { "<double>": 0.1 }
                                                            }
                                                        }
                                                    }
                                                ]
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            );
            jamEngine.jsonPlay
            (
                "make",
                {
                    "target": { "<reference>": [ { "adjustmentLayer": { "<class>": null } } ] },
                    "using":
                    {
                        "<object>":
                        {
                            "adjustmentLayer":
                            {
                                "name": { "<string>": "Levels" },
                                "type":
                                {
                                    "<object>":
                                    {
                                        "levels":
                                        {
                                            "adjustment":
                                            {
                                                "<list>":
                                                [
                                                    {
                                                        "<object>":
                                                        {
                                                            "levelsAdjustment":
                                                            {
                                                                "channel": jamHelpers.toChannelReference ("composite"),
                                                                "input": jamHelpers.toIntegerList ([ 10, 245 ]),
                                                                "gamma": { "<double>": 0.8 },
                                                                "output": jamHelpers.toIntegerList ([ 20, 235 ])
                                                            }
                                                        }
                                                    },
                                                    {
                                                        "<object>":
                                                        {
                                                            "levelsAdjustment":
                                                            {
                                                                "channel": jamHelpers.toChannelReference ("red")
                                                            }
                                                        }
                                                    },
                                                    {
                                                        "<object>":
                                                        {
                                                            "levelsAdjustment":
                                                            {
                                                                "channel": jamHelpers.toChannelReference ("green"),
                                                                "input": jamHelpers.toIntegerList ([ 206, 255 ]),
                                                                "gamma": { "<double>": 1.2 }
                                                            }
                                                        }
                                                    },
                                                    {
                                                        "<object>":
                                                        {
                                                            "levelsAdjustment":
                                                            {
                                                                "channel": jamHelpers.toChannelReference ("blue"),
                                                                "gamma": { "<double>": 1.35 }
                                                            }
                                                        }
                                                    }
                                                ]
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            );
            break;
        case "Photo Filter":
            jamEngine.jsonPlay
            (
                "make",
                {
                    "target": { "<reference>": [ { "adjustmentLayer": { "<class>": null } } ] },
                    "using":
                    {
                        "<object>":
                        {
                            "adjustmentLayer":
                            {
                                "name": { "<string>": "Photo Filter" },
                                "type":
                                {
                                    "<object>":
                                    {
                                        "photoFilter":
                                        {
                                            "color": jamHelpers.toColorObject ([ "RGBColor", [ 255, 216, 0 ] ]),
                                            "density": { "<integer>": 80 },
                                            "preserveLuminosity": { "<boolean>": true }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            );
            break;
        case "Posterize":
            jamEngine.jsonPlay
            (
                "make",
                {
                    "target": { "<reference>": [ { "adjustmentLayer": { "<class>": null } } ] },
                    "using":
                    {
                        "<object>":
                        {
                            "adjustmentLayer":
                            {
                                "name": { "<string>": "Posterize | Luminosity" },
                                "mode": { "<enumerated>": { "blendMode": "luminosity" } },
                                "type": { "<object>": { "posterize": { "levels": { "<integer>": 3 } } } }
                            }
                        }
                    }
                }
            );
            break;
        case "Selective Color":
            jamEngine.jsonPlay
            (
                "make",
                {
                    "target": { "<reference>": [ { "adjustmentLayer": { "<class>": null } } ] },
                    "using":
                    {
                        "<object>":
                        {
                            "adjustmentLayer":
                            {
                                "name": { "<string>": "Selective Color" },
                                "type":
                                {
                                    "<object>":
                                    {
                                        "selectiveColor":
                                        {
                                            "method": { "<enumerated>": { "correctionMethod": "absolute" } },
                                            "colorCorrection":
                                            {
                                                "<list>":
                                                [
                                                    {
                                                        "<object>":
                                                        {
                                                            "colorCorrection":
                                                            {
                                                                "colors": { "<enumerated>": { "colors": "reds" } },
                                                                "cyan": { "<unitDouble>": { "percentUnit": 0 } },
                                                                "magenta": { "<unitDouble>": { "percentUnit": 100 } },
                                                                "yellowColor": { "<unitDouble>": { "percentUnit": 100 } },
                                                                "black": { "<unitDouble>": { "percentUnit": 0 } }
                                                            }
                                                        }
                                                    },
                                                    {
                                                        "<object>":
                                                        {
                                                            "colorCorrection":
                                                            {
                                                                "colors": { "<enumerated>": { "colors": "neutrals" } },
                                                                "cyan": { "<unitDouble>": { "percentUnit": -20 } },
                                                                "magenta": { "<unitDouble>": { "percentUnit": 50 } },
                                                                "yellowColor": { "<unitDouble>": { "percentUnit": 20 } },
                                                                "black": { "<unitDouble>": { "percentUnit": -8 } }
                                                            }
                                                        }
                                                    },
                                                    {
                                                        "<object>":
                                                        {
                                                            "colorCorrection":
                                                            {
                                                                "colors": { "<enumerated>": { "colors": "blacks" } },
                                                                "cyan": { "<unitDouble>": { "percentUnit": 100 } },
                                                                "magenta": { "<unitDouble>": { "percentUnit": -31 } },
                                                                "yellowColor": { "<unitDouble>": { "percentUnit": -67 } },
                                                                "black": { "<unitDouble>": { "percentUnit": -40 } }
                                                            }
                                                        }
                                                    }
                                                ]
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            );
            break;
        case "Threshold":
            jamEngine.jsonPlay
            (
                "make",
                {
                    "target": { "<reference>": [ { "adjustmentLayer": { "<class>": null } } ] },
                    "using":
                    {
                        "<object>":
                        {
                            "adjustmentLayer":
                            {
                                "name": { "<string>": "Threshold | Darken" },
                                "mode": { "<enumerated>": { "blendMode": "darken" } },
                                "type": { "<object>": { "thresholdClassEvent": { "level": { "<integer>": 108 } } } }
                            }
                        }
                    }
                }
            );
            break;
        case "Vibrance":
            jamEngine.jsonPlay
            (
                "make",
                {
                    "target": { "<reference>": [ { "adjustmentLayer": { "<class>": null } } ] },
                    "using":
                    {
                        "<object>":
                        {
                            "adjustmentLayer":
                            {
                                "name": { "<string>": "Vibrance" },
                                "type":
                                {
                                    "<object>":
                                    {
                                        "vibrance":
                                        {
                                            "vibrance": { "<integer>": 100 },
                                            "saturation": { "<integer>": 20 }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            );
            break;
    }
}

//------------------------------------------------------------------------------

var appVersion = parseFloat (app.version);
if (getParameters ())
{
    jamEngine.meaningfulIds = true;
    jamEngine.jsonPlay ("open", { "target": { "<path>": "Factory.jpg" } });
    if (desiredAdjustment === allAdjustments)
    {
        var resultDescriptorObj = jamEngine.jsonGet ([ { "property": { "<property>": "documentID" } }, { "document": { "<enumerated>": { "ordinal": "first" } } } ]);
        var docId = resultDescriptorObj["documentID"]["<integer>"];
        var docIds = [ ];
        for (var k in adjustments)
        {
            if (adjustments.hasOwnProperty (k))
            {
                if (appVersion >= adjustments[k]["minVersion"])
                {
                    jamEngine.jsonPlay ("select", { "target": { "<reference>": [ { "document": { "<identifier>": docId } } ] } });
                    processAdjustment (k);
                    resultDescriptorObj = jamEngine.jsonGet ([ { "property": { "<property>": "documentID" } }, { "document": { "<enumerated>": { "ordinal": "first" } } } ]);
                    docIds.unshift (resultDescriptorObj["documentID"]["<integer>"]);
                }
            }
        }
        if (reverseAllDocs)
        {
            docIds.reverse ();
        }
        for (var i = 0; i < docIds.length; i++)
        {
            jamEngine.jsonPlay ("select", { "target": { "<reference>": [ { "document": { "<identifier>": docIds[i] } } ] } });  
        }
    }
    else
    {
        processAdjustment (desiredAdjustment);
    }
}

//------------------------------------------------------------------------------

